I2C Peripheral Testing

Reading and Writing EEPROM

Adding Code to Vitis Application Project

Right-click on src to create a new folder:

image-20250710140513635

Create related .c and .h files:

image-20250710140624298

As shown below:

image-20250710142508748

Compilation and Debugging

At this point, similar to GPIO operations, if there are custom header files, the file directory needs to be added to the path. The steps are as above, and the final result is as shown below:

image-20250710143029923

Core Code

Debugging Results

image-20250710090844195

Reading Temperature and Humidity Sensor

Adding Code to Vitis Application Project

Right-click on src to create a new folder:

image-20250710140513635

Create related .c and .h files, as shown below:

image-20250710143404518

Compilation and Debugging

Core Code

 

Debugging Results

image-20250710090903681

Reading and Writing RTC Clock

Adding Code to Vitis Application Project

Right-click on src to create a new folder:

image-20250710140513635

Create related .c and .h files, as shown below:

image-20250710143628291

Compilation and Debugging

Core Code

Debugging Results

image-20250710090924915

 

 

Accessing RTC via Kernel Built-in Driver

Modifying the Device Tree

Open /home/mind/petalinux_projects/petalinux-mind/project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi, and add the following content:

After making the changes, save and exit, then re-run the following steps:

Copy the BOOT.BIN, boot.scr, and image.ub files from the project directory images -> linux to the FAT partition of the SD card. The file system remains unchanged. Restart the development board.

After the system restarts, check the /dev/ directory for any RTC-related device files, as shown below:

image-20250821142505644

You can see there are two device files in the /dev directory: rtc and rtc0, where rtc is a soft link to rtc0. This rtc0 corresponds to our pcf8563 device. If no RTC devices are registered (using the Linux RTC device driver framework) in the system, there will be no rtc device files in the /dev directory. If multiple RTC devices are registered in the kernel, they will be named rtc0, rtc1, rtc2, etc. There is an rtc directory under /sys/class, and the files in this directory are as follows:

image-20250821142642052

Here, rtc0 corresponds to the pcf8563 device.

RTC Time Viewing and Setting

(1) View time:

The date command shows the system clock, not the RTC clock. The system clock is maintained by the kernel after system startup, not by the RTC hardware. Use the hwclock command to view the RTC clock.

(2) Set RTC time:

After setting, use the date command again to see that the current time has been changed.

(3) Write to RTC:

At this point, the time will not be lost even after a system restart. If the development board has a coin cell battery attached, the time will not be lost even if the board is powered off.